package com.m1905.lib.download.util;

import java.io.Closeable;
import java.io.InputStream;

public final class IoUtils {

    private IoUtils() {

    }

    /**
     * Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
     */
    public static void closeQuietly(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (RuntimeException rethrown) {
                throw rethrown;
            } catch (Exception ignored) {
            }
        }
    }

    public static String toString(InputStream input) {
        StringBuilder sb = new StringBuilder();
        try {
            byte[] buf = new byte[4096];
            int size;
            while ((size = input.read(buf)) != 0) {
                sb.append(new String(buf, 0, size));
            }
            input.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }


}
